package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/10/10 15:19
 * @description：
 */
public class 和为偶数的子数组个数 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.numOfEvenSubarrays(new int[]{1, 2, 5}));
    }

    public class Solution {
        public int numOfEvenSubarrays(int[] arr) {
            final int MOD = 1000000007;
            int even = 1;
            int odd = 0;
            int count = 0;
            int sum = 0;
            for (int i = 0; i < arr.length; i++) {
                sum += arr[i];
                count = (count + sum % 2 == 0 ? even : odd) % MOD;
                if (sum % 2 == 0) {
                    even++;
                } else {
                    odd++;
                }
            }
            return count;
        }
    }

}
